//----BEGIN LICENSE----//
/*****************************************************************\
** prevalentLite - sqlite3 persistence object library 
**
** Copyright (C) 2008 Philip R. Schuchardt
**
** This program is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation, either version 3 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program.  If not, see <http://www.gnu.org/licenses/>.
**
*****************************************************************/
//----END LICENSE----//
/*!
  \class plLongLong plLongLong.h <plLongLong>
  \brief plLongLong is a database aware integer.

  plLongLong can be used and should be used in the same way as a normal integer.  Make sure plLongLong::Setup() is called before using the class.  Without calling plLongLong::Setup(), the database doesn't know how to get or commit data.

  For example:
  \code

  plLongLong test;
  test.Setup("test", this);
  test = 5;
  test += 10;
  test = test * test;

  int temp = test;
  temp = 1000;
  test = temp;

   \endcode

  */

//Our includes
#include "plLongLong.h"
#include "plDatabase.h"
#include "plObject.h"

//////////////////////////////////////////////// Public ////////////////////////////////////////////////////

//Constructor
plLongLong::plLongLong() : plData() {
    Value = 0;
    Cached = false;
}

//Constructor
plLongLong::plLongLong(long long value) : plData(){
    Value = value;
    Disabled = true;
}

//Copy Constructor
plLongLong::plLongLong(const plLongLong& obj) : plData() {
    Copy(obj);
}

//Accessor
long long plLongLong::Data() {
    plData::GetData();
    return Value;
}

//Modifier
void plLongLong::SetData(long long value) {
    Value = value;
    plData::SetData();
}


//Operator overloading
void plLongLong::operator=(long long value) {
    SetData(value);
}

//Assignment overaloading
void plLongLong::operator=(const plLongLong& obj) {
    Copy(obj);
}

plLongLong::operator long long() {
    return Data();
}

//Binds the data with the statement
void plLongLong::Bind(sqlite3_stmt* statement, int index) const {
    sqlite3_bind_int64(statement, index, Value);
}

//Gets the data from the current statement
void plLongLong::Column(sqlite3_stmt* statement, int index ) {
    Value = sqlite3_column_int64(statement, index);
}

//Does a smart copy of the object
void plLongLong::Copy(const plLongLong& obj) {
    SetData(obj.Value);
}


